class MineController < ApplicationController
  before_action :exception_stb
  skip_before_action :exception_stb, only: [:index]

  def index
  end

  def song_fav
    @items = current_user.song_fav.songs.joins(:song_fav_songs).order('song_favs_songs.updated_at desc')
    @picks = current_user.picklist.songs.pluck(:id)
    @favs = @items.pluck(:id)
    render 'video_page'
  end

  def playlist_fav
    # 歌单收藏是歌单与歌手的融合数组
    collection = current_user.playlists.ordered + current_user.singers.ordered

    # 样式原因, 保持上下分离
    @items = if collection.present?
               if collection.count >= 11
                 collection.each_slice((collection.count / 2.0).ceil)
               else
                 collection.each_slice(5)
               end
             else
               []
             end
  end

  def picklist
    @items = current_user.picklist.songs.joins(:picklist_songs).order('picklists_songs.updated_at desc')
    @picks = @items.pluck(:id)
    @favs = current_user.song_fav.songs.pluck(:id)
    render 'video_page'
  end

  def history
    @items = current_user.history.songs.joins(:history_songs).order('histories_songs.updated_at desc')
    @picks = current_user.picklist.songs.pluck(:id)
    @favs = current_user.song_fav.songs.pluck(:id)
    render 'video_page'
  end
end
